﻿using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Browser;

namespace LightReader
{
    public static class DisplayHelper
    {
        // snagged from the RSS reader sample found 
        // here: http://code.msdn.microsoft.com/silverlightws/Release/ProjectReleases.aspx?ReleaseId=601
        // slightly modified by Michael Eaton on 3/15/2008.
        public static string Convert(string value)
        {
            // Remove HTML tags and empty newlines and spaces
            string temp = HttpUtility.HtmlDecode(value);
            temp = Regex.Replace(temp, "</p>", "\n\n");
            string returnString = Regex.Replace(temp, "<.*?>", "");
            returnString = Regex.Replace(returnString, @"\n+\s+", "\n\n");

            // Decode HTML entities
            returnString = HttpUtility.HtmlDecode(returnString);

            return returnString;
        }
    }
}
